<?php
class Qxmanage_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
        if(isset($xxfget['type'])){
            $type=$xxfget['type'];
        }
        if(!$type){
            $result=xdb::getInstance()->getarray('select u.id as uid,ul.id as ulid,username,realname,lname from user as u,list as l,user_list as ul where u.id=ul.uid and l.id=ul.lid');
            $userselect=xdb::getInstance()->getarray('select id,realname,mphone from user');
            $listselect=xdb::getInstance()->getarray('select id,lname from list');
            $this::show('qxmanage',compact('result','userselect','listselect'));
        }else{
            if($type=='add'){
                $array=array();
                $array2=array();
                $uid=$_POST['uid'];
                $lid=$_POST['lid'];
                $array['uid']=$uid;
                $array['lid']=$lid;
                $array2['uid']=$uid;
                $array2['lid']=$lid;
                echo xdb::getInstance()->indb('user_list', $array, $array2);
            }elseif ($type=='del'){
                $array=array();
                $array['id']=$_POST['ulid'];
                echo xdb::getInstance()->deldb('user_list', $array);
            }elseif($type=="bak"){
				$t=time();
				//$result = exec(str_replace("?",$t,gconf("dbcon","db_bak")));
				//$result = exec(str_replace("?",$t,gconf("dbcon","db_bak")));
				echo $t."未实装";
			}elseif($type=='all'){
			    $lid=$xxfget['lid'];
			    $list=xdb::getInstance()->getarray('select * from list order by paixu');
			    $result=xdb::getInstance()->getarray('select `user`.id as id,uid,username,realname,zhiwu from `user` LEFT JOIN user_list on `user`.id=user_list.uid and user_list.lid='.$lid);
			    $this::show('qxmanage_all',compact('result','lid','list'));
			}elseif($type=='allsub'){
			    $chall=explode(",", $_POST['chall']);
			    $lid=$_POST['lid'];
			    for($i=1;$i<count($chall);$i++){
			        $ch=explode("_", $chall[$i]);
			        $array=array();
			        $array2=array();
			        $array['lid']=$lid;
			        $array['uid']=$ch[0];
			        $array2['lid']=$lid;
			        $array2['uid']=$ch[0];
			        if($ch[1]){
			            xdb::getInstance()->indb("user_list", $array, $array2);
			        }else{
			            xdb::getInstance()->deldb("user_list", $array);
			        }
			    }
			    echo 1;
			}
        }
    }
}